package com.tchhy.mvplibrary.ui.activity

import android.os.Bundle
import com.tchhy.mvplibrary.presenter.BasePresenter
import com.tchhy.mvplibrary.presenter.view.BaseView
import com.tchhy.mvplibrary.ui.inject.InjectUtils
import com.tchhy.provider.rx.BaseException

/**
 *
 * 每个业务Activity必须实现
 *
 * Author: wfy
 *
 * time: 2018/8/22
 *
 */

abstract class BaseMvpActivity<T : BasePresenter<*>> : BaseActivity(), BaseView {
     lateinit var mPresenter: T

    override fun showLoading() {
        if (isShowLoading() && mProgressLoadingDialog?.isShowing == false) {
            mProgressLoadingDialog?.showLoading()
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        InjectUtils.injectActivity(this)
    }

    open fun isShowLoading(): Boolean {
        return true
    }

    override fun dismissLoading() {
        if (mProgressLoadingDialog?.isShowing == true) {
            mProgressLoadingDialog?.dismissLoading()
        }
    }

    override fun onError(throwable: BaseException) {
    }

    override fun onError(errorMessage: String) {

    }
}